<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Taskflow Handbook</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname"><a href="https://taskflow.github.io/">Taskflow</a>
   &#160;<span id="projectnumber">3.0.0-Master-Branch</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('ParallelTransformCUDA.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Parallel Transforms (cudaFlow) </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>cudaFlow provides a template function that applies the given function to a range and sotres the result in another range</p>
<h1><a class="anchor" id="IteratorBasedParallelTransformCUDA"></a>
Iterator-based Parallel Transforms</h1>
<p>Iterator-based parallel-transform applies the given transform function to a range of items and store the result in another range specified by two iterators, <code>first</code> and <code>last</code>. The two iterators are typically two raw pointers to the first element and the next to the last element in the range in GPU memory space. The task created by <a class="el" href="classtf_1_1cudaFlow.html#a552f2da29009113beee4ee90bc95ae65" title="applies a callable to a source range and stores the result in a target range">tf::cudaFlow::transform(I first, I last, C&amp;&amp; callable, S... srcs)</a> represents a kernel of parallel execution for the following loop:</p>
<div class="fragment"><div class="line"><span class="keywordflow">while</span> (first != last) {</div>
<div class="line">  *first++ = callable(*src1++, *src2++, *src3++, ...);</div>
<div class="line">}</div>
</div><!-- fragment --><p>The two iterators, <code>first</code> and <code>last</code>, are typically two raw pointers to the first element and the next to the last element in the range. The following example creates a <code>transform</code> kernel that assigns each element, starting from <code>gpu_data</code> to <code>gpu_data + 1000</code>, to the sum of the corresponding elements at <code>gpu_data_x</code>, <code>gpu_data_y</code>, and <code>gpu_data_z</code>.</p>
<div class="fragment"><div class="line">taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a60d7a666cab71ecfa3010b2efb0d6b57">emplace</a>([](<a class="code" href="classtf_1_1cudaFlow.html">tf::cudaFlow</a>&amp; cf){</div>
<div class="line">  <span class="comment">// ... create gpu tasks</span></div>
<div class="line">  <span class="comment">// create a kernel for computing gpu_data[i] = gpu_data_x[i] + gpu_data_y[i] + gpu_data_z[i]</span></div>
<div class="line">  <a class="code" href="classtf_1_1cudaTask.html">tf::cudaTask</a> task = cf.<a class="code" href="classtf_1_1cudaFlow.html#a552f2da29009113beee4ee90bc95ae65">transform</a>(</div>
<div class="line">    gpu_data, gpu_data + 1000, </div>
<div class="line">    [] __device__ (<span class="keywordtype">int</span>&amp; xi, <span class="keywordtype">int</span>&amp; yi, <span class="keywordtype">int</span> &amp;zi) { <span class="keywordflow">return</span> xi + yi + zi; },</div>
<div class="line">    gpu_data_x, gpu_data_y, gpu_data_z</div>
<div class="line">  ); </div>
<div class="line">});</div>
</div><!-- fragment --><p>Each iteration is independent of each other and is assigned one kernel thread to run the callable. Since the callable runs on GPU, it must be declared with a <code>__device__</code> specifier.</p>
<h1><a class="anchor" id="ParallelTransformCUDAMiscellaneousItems"></a>
Miscellaneous Items</h1>
<p>The parallel-transform algorithm is also available in <a class="el" href="classtf_1_1cudaFlowCapturerBase.html#a44fb0c626c46de1bb95369e33194f5c7" title="captures a kernel that applies a callable to a source range and stores the result in a target range">tf::cudaFlowCapturer::transform</a>. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div class="ttc" id="aclasstf_1_1cudaFlow_html_a552f2da29009113beee4ee90bc95ae65"><div class="ttname"><a href="classtf_1_1cudaFlow.html#a552f2da29009113beee4ee90bc95ae65">tf::cudaFlow::transform</a></div><div class="ttdeci">cudaTask transform(I first, I last, C &amp;&amp;callable, S... srcs)</div><div class="ttdoc">applies a callable to a source range and stores the result in a target range</div><div class="ttdef"><b>Definition:</b> cuda_flow.hpp:935</div></div>
<div class="ttc" id="aclasstf_1_1FlowBuilder_html_a60d7a666cab71ecfa3010b2efb0d6b57"><div class="ttname"><a href="classtf_1_1FlowBuilder.html#a60d7a666cab71ecfa3010b2efb0d6b57">tf::FlowBuilder::emplace</a></div><div class="ttdeci">Task emplace(C &amp;&amp;callable)</div><div class="ttdoc">creates a static task</div><div class="ttdef"><b>Definition:</b> flow_builder.hpp:627</div></div>
<div class="ttc" id="aclasstf_1_1cudaFlow_html"><div class="ttname"><a href="classtf_1_1cudaFlow.html">tf::cudaFlow</a></div><div class="ttdoc">class for building a CUDA task dependency graph</div><div class="ttdef"><b>Definition:</b> cuda_flow.hpp:47</div></div>
<div class="ttc" id="aclasstf_1_1cudaTask_html"><div class="ttname"><a href="classtf_1_1cudaTask.html">tf::cudaTask</a></div><div class="ttdoc">handle to a node of the internal CUDA graph</div><div class="ttdef"><b>Definition:</b> cuda_task.hpp:53</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="GPUAlgorithms.html">GPU Algorithms</a></li>
    <li class="footer">Generated by <a href="http://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20 </li>
  </ul>
</div>
</body>
</html>
